package com.xzz.tree;

/**
 * @author: hhz
 * @create: 2022-01-19 17:28
 * 100. 相同的树
 **/
public class IsSameTree {
    public static void main(String[] args) {
        TreeNode node1 = new TreeNode(10);
        TreeNode node2 = new TreeNode(5);
        TreeNode node3 = new TreeNode(15);
        TreeNode node4 = new TreeNode(10);
        TreeNode node5 = new TreeNode(5);
        TreeNode node6 = new TreeNode(15);
        node1.left = node2;
        node1.right = node3;
        node4.left = node5;
        node5.right = node6;
        System.out.println(isSameTree(node1, node4));
    }

    public static boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        if (p.val != q.val) {
            return false;
        }
        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}
